package loteria.dao;

public class LoteriaDAOFactory {
	private static LoteriaDAOFactory factory;
	
    
    private LoteriaDAOFactory() {
    }
    
    public static LoteriaDAOFactory getInstance() {
            if (factory == null) {
                    factory = new LoteriaDAOFactory();
            }
            
            return factory;
    }
    
    public LoteriaDAO getDAO(String name) {
    	LoteriaDAO dao = null;
            
            if (name.equals(LoteriaDAO.hsqldb)) {
            		dao = LoteriasDAOImplDB.getDAO();
            		
            } else if (name.equals(LoteriaDAO.hibernate)) {
                    dao = LoteriasDAOImplHibernate.getDAO();
            } else {
                    try {
                            dao = (LoteriaDAO) Class.forName(name).newInstance();
                            
                    } catch (InstantiationException e) {
                            e.printStackTrace();
                    } catch (IllegalAccessException e) {
                            e.printStackTrace();
                    } catch (ClassNotFoundException e) {
                            e.printStackTrace();
                    }
            }
            
            return dao;
    }
}

